<template>
  <swiper :options="swiperOption">
    <swiper-slide v-for="(slide, index) in swiperSlides" :key="index">
      <h1>
        I'm Slide {{ slide }}
      </h1>
    </swiper-slide>
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>

<script>
  // demo
  import 'swiper/dist/css/swiper.css'
  import { swiper, swiperSlide } from 'vue-awesome-swiper'

  export default {
    name: 'carrousel',
    data() {
      return {
        swiperOption: {
          pagination: {
            el: '.swiper-pagination'
          },
          autoplay: {
            delay: 500, // 延迟时间
            disableOnInteraction: false // 用户操作后不停止播放
          },
          speed: 500, // 速度
          loop: true, // 最后一页事件不能绑定
          // initialSlide: this.pageIndex, // 默认页面
          direction: 'horizontal', // 垂直滚动
          // 注意不要跟 vue-router 的 hash 模式冲突了, 两者不可共用
          // hashNavigation: {
          //   replaceState: true, // 翻页不产生历史记录
          //   watchState: true,
          // },
          hashNavigation: false,
          observer: true, // 子元素发生变化自动初始化swiper
          observeParents: true, // 父元素发生变化自动初始化swiper
        },
        swiperSlides: [1, 2, 3, 4, 5]
      }
    },
    mounted() {
      setInterval(() => {
        if (this.swiperSlides.length < 10) {
          this.swiperSlides.push(this.swiperSlides.length + 1)
        }
      }, 3000)
    },
    components: {
      swiper,
      swiperSlide
    }
  }
</script>
